﻿	      <?php include("conn.php");
             mysql_query('SET NAMES UTF8'); 

	  

class MyPrizeBean
{
	
	public $images;
	public $goodsid;
	public $title;
	public $distance;
	public $content;
	public $reply;
	public $like;
	public $price;
	public $pingfen;
	public $spingfen;
	public $yuanjia;
	public $name;
	public $address;
	public $summary;
	public $tel;
	public $pings;
	public $shopid;
	public $youhui;
	public $images2;
	
	function __construct($images,$goodsid,$title,$distance,$content,$reply,$like,$price,$pingfen,$spingfen,$yuanjia,$name,$address,$summary,$tel,$pings,$shopid,$youhui,$images2)
	{
		
		$this->images      = $images;
		$this->goodsid      = $goodsid;
		$this->title      = $title;
		$this->distance      = $distance;
		$this->content      = $content;
		$this->reply      = $reply;
		$this->like      = $like;
		$this->price      = $price;
		$this->pingfen      = $pingfen;
		$this->spingfen      = $spingfen;
		$this->yuanjia      = $yuanjia;
		$this->name      = $name;
		$this->address      = $address;
		$this->summary      = $summary;
		$this->tel      = $tel;
		$this->pings      = $pings;
		$this->shopid      = $shopid;
		$this->youhui      = $youhui;
		$this->images2      = $images2;
	
	}
}




   $rert31=mysql_query("select *from goods where goodsid='".$_REQUEST[goodsid]."'");
  $prize = array();
 $rowf=mysql_fetch_array($rert31);

  
     $rert32=mysql_query("select *from user where userid='".$_REQUEST[userid]."'");
     $rowf3=mysql_fetch_array($rert32);
	 
	     $rert33=mysql_query("select *from shop where shopid='".$rowf[shopid]."'");
     $rowf4=mysql_fetch_array($rert33);
	 

       $longitude1=$rowf3['longitude'];$latitude1=$rowf3['latitude'];$longitude2=$rowf['longitude'];$latitude2=$rowf['latitude'];
	   
	   function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2) {
    $theta = $longitude1 - $longitude2;
    $miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
    $miles = acos($miles);
    $miles = rad2deg($miles);
    $miles = $miles * 60 * 1.1515;
    $kilometers = $miles * 1.609344;
    return compact('kilometers'); 

}


$distance = getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2);
foreach ($distance as $unit => $value) {
    $dic= number_format($value,1);
}

if($_REQUEST[userid]!="")
{
$juli=$dic;
}
else
{
$juli=0;
}
   $rert33=mysql_query("select *from shop where shopid='".$rowf[shopid]."'");

 $rowf3=mysql_fetch_array($rert33);
 
   $rert38=mysql_query("select *from mycoupon where goodsid='".$rowf23[goodsid]."' and userid='".$_GET[userid]."'");//优惠券

 $rowf8=mysql_fetch_array($rert38);
 
 
 	if($rowf8!=false)
	{
	$youhuis=$rowf8[price];
	}
	else
	{
	$youhuis=0;
	}
	
	
 $countt=mysql_query("select SUM(service) from goodsreply  where   shopid ='".$rowf['shopid']."'");

//店铺评论数
$rst=mysql_fetch_array($countt);
$sump=$rst[0];

$countgs=mysql_query("select count(*) from goodsreply  where   goodsid ='".$rowf['goodsid']."'");

//店铺
$rsgs=mysql_fetch_array($countgs);
$togs=$rsgs[0];
 $sping=round(($sump/$togs),2);
 
 
$counts=mysql_query("select SUM(service) from goodsreply  where   goodsid ='".$rowf['goodsid']."'");

//评论数
$rss=mysql_fetch_array($counts);
$sum=$rss[0];






$count=mysql_query("select count(*) from goodsreply  where   goodsid ='".$rowf['goodsid']."'");

//评论数
$rs=mysql_fetch_array($count);
$totalNumber=$rs[0];
$ping=round(($sum/$totalNumber),2);

$count1=mysql_query("select count(*) from likes  where   goodsid ='".$rowf['goodsid']."'");

//点赞数
$rs1=mysql_fetch_array($count1);
$totalNumber1=$rs1[0];

if($totalNumber!=0)
{
$sum=$totalNumber;
$ping=round(($sum/$totalNumber),2);
}
else
{
$ping=5;

}

if ($ping < 2) {
                            $pinfen = "<span></span><span class='empty'></span><span class='empty'></span><span class='empty'></span><span class='empty'></span>";
                        } 
						
						 else if ($ping < 3 and $ping > 2) {
                            $pinfen = "<span></span><span></span><span class='empty'></span><span class='empty'></span><span class='empty'></span>";
                        } 
						
						 else if ($ping < 4 and $ping > 3) {
                           $pinfen = "<span></span><span></span><span ></span><span class='empty'></span><span class='empty'></span>";
                        }
						 else if ($ping < 5 and $ping > 4) {
                           $pinfen = "<span></span><span></span><span ></span><span></span><span class='empty'></span>";
                        }
						 else  {
                           $pinfen = "<span></span><span></span><span ></span><span ></span><span ></span>";
                        }
						
                    $ime=array();
                 $ime=$rowf['images'];
		         $de=explode("," ,$ime);
				 $topimges="";
		  foreach($de as $key => $tmp_name ) { if($tmp_name!=""){
		     
			 $topimges.="<div class=swiper-slide data-hash=slide2 ><img src='http://120.24.0.10/xyt/api/".$tmp_name."' alt= /></div>";
			   
			       }
		            }
					
					$shopimages=$de[0];

$addresss=$rowf3['city'].$rowf3['dian'].$rowf3['address'];
   
		$prize[] = new MyPrizeBean($topimges,$rowf['goodsid'],$rowf['title'],$juli,$rowf['content'],$totalNumber,$rowf['xihuan'],$rowf['price'],$sping,$ping,$rowf['yuanjia'],$rowf3['name'],$addresss,$rowf['summary'],$rowf3['tel'],$pinfen,$rowf3['shopid'],$youhuis,$shopimages);
		


echo json_encode($prize);


?>